package com.zhang.apidriver.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 类功能描述
 *
 * @author Kye
 * @date 2025-04-21
 */
@Configuration
public class CrosConfig implements WebMvcConfigurer {
	@Override
	public void addCorsMappings(CorsRegistry registry) {
		registry.addMapping("/**")
				// 明确指定前端地址（不要用通配符）
				.allowedOriginPatterns("http://192.168.0.103:3001")
				.allowCredentials(true)
				// 显式包含 OPTIONS 方法
				.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
				.allowedHeaders("*")
				.maxAge(3600);
	}
}